package mango3.myapplication.adapter;

import android.support.v7.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

import mango3.myapplication.R;
import mango3.myapplication.ViewHolder.MyRecycleViewHolder;

/**
 * Created by Administrator on 2015/11/18.
 */


public class MyStaggeredViewAdapter extends  RecyclerView.Adapter<MyRecycleViewHolder> {

    LayoutInflater layoutInflater;

    int [] heights;

    List<String> urls=new ArrayList<String>();

    public MyStaggeredViewAdapter(LayoutInflater layoutInflater) {
        this.layoutInflater = layoutInflater;
        heights = new int[10];

        urls.add("http://y3.ifengimg.com/a/2015_41/1b8a43163088718.jpg");//
        urls.add("http://img0.imgtn.bdimg.com/it/u=1839214133,2905767713&fm=21&gp=0.jpg");
        urls.add("http://images.ali213.net/picfile/pic/2013-01-22/927_p88.jpg");
        urls.add("http://img0.imgtn.bdimg.com/it/u=1839214133,2905767713&fm=21&gp=0.jpg");
        urls.add("http://images.ali213.net/picfile/pic/2013-01-22/927_p88.jpg");
        urls.add("http://a3.att.hudong.com/64/29/01300000335934124083290423682.jpg");
        urls.add("http://pic.pp3.cn/uploads//allimg/111114/160U51008-6.jpg");
        urls.add("http://a3.att.hudong.com/64/29/01300000335934124083290423682.jpg");
        urls.add("http://a3.att.hudong.com/64/29/01300000335934124083290423682.jpg");
        urls.add("http://a3.att.hudong.com/64/29/01300000335934124083290423682.jpg");

        for(int i=0;i<10;i++)
        {
            heights[i] = (int) (Math.random()*300+300);
        }

    }

    @Override
    public MyRecycleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

            View itemView = layoutInflater.inflate(R.layout.sta_item,parent,false);

            MyRecycleViewHolder myRecycleViewHolder = new MyRecycleViewHolder(itemView);

        return myRecycleViewHolder;
    }
    @Override
    public void onBindViewHolder(MyRecycleViewHolder holder, int position) {

        ViewGroup.LayoutParams mLayoutParams = holder.iv.getLayoutParams();
        mLayoutParams.height = heights[position];
        holder.iv.setLayoutParams(mLayoutParams);
        ImageLoader.getInstance().displayImage(urls.get(position), holder.iv);
    }

    @Override
    public int getItemCount() {
        return urls.size();
    }


}
